package com.zg.ktcomwan.base

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

/***
 * @Author:      zxd
 * @CreateDate:  2021/6/3 14:02
 * @Description:
 */
open class BaseViewModel : ViewModel() {
    private val error by lazy { MutableLiveData<Exception>() }

    // UI
    fun launchUI(block: suspend CoroutineScope.() -> Unit) = viewModelScope.launch {
        try {
            block()
        } catch (e: Exception) {
            error.value = e
        }
    }

}